package com.flymobi.mshop.util;

import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class ShopCarVo {
	private static final ShopCarVo instance = new ShopCarVo();

	private ShopCarVo() {
	}

	public static ShopCarVo getInstance() {
		return instance;
	}

	public class CurPropValueVo {
		private String name;
		private String value;

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Object#hashCode()
		 */
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + ((name == null) ? 0 : name.hashCode());
			return result;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Object#equals(java.lang.Object)
		 */
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			CurPropValueVo other = (CurPropValueVo) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (name == null) {
				if (other.name != null)
					return false;
			} else if (!name.equals(other.name))
				return false;
			return true;
		}

		/**
		 * @return the name
		 */
		public String getName() {
			return name;
		}

		/**
		 * @param name
		 *            the name to set
		 */
		public void setName(String name) {
			this.name = name;
		}

		/**
		 * @return the value
		 */
		public String getValue() {
			return value;
		}

		/**
		 * @param value
		 *            the value to set
		 */
		public void setValue(String value) {
			this.value = value;
		}

		private ShopCarVo getOuterType() {
			return ShopCarVo.this;
		}
	}

	public class Prod {
		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Object#hashCode()
		 */
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime
					* result
					+ ((curPropValueList == null) ? 0 : curPropValueList
							.hashCode());
			result = prime * result + (int) (id ^ (id >>> 32));
			return result;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Object#equals(java.lang.Object)
		 */
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Prod other = (Prod) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (curPropValueList == null) {
				if (other.curPropValueList != null)
					return false;
			} else if (!curPropValueList.equals(other.curPropValueList))
				return false;
			if (id != other.id)
				return false;
			return true;
		}

		private long id;
		private long count;
		private Map<String, Object> prod;
		public float getTotalPrice() {
			return new Float(prod.get("saleprice").toString()) * count;
		}

		/**
		 * @return the prod
		 */
		public Map<String, Object> getProd() {
			return prod;
		}

		/**
		 * @param prod
		 *            the prod to set
		 */
		public void setProd(Map<String, Object> prod) {
			this.prod = prod;
		}

		private Set<CurPropValueVo> curPropValueList = new HashSet<CurPropValueVo>();
		private Date time;

		/**
		 * @return the curPropValueList
		 */
		public Set<CurPropValueVo> getCurPropValueList() {
			return curPropValueList;
		}

		/**
		 * @param curPropValueList
		 *            the curPropValueList to set
		 */
		public void setCurPropValueList(Set<CurPropValueVo> curPropValueList) {
			this.curPropValueList = curPropValueList;
		}

		/**
		 * @return the id
		 */
		public long getId() {
			return id;
		}

		/**
		 * @param id
		 *            the id to set
		 */
		public void setId(long id) {
			this.id = id;
		}

		/**
		 * @return the count
		 */
		public long getCount() {
			return count;
		}

		/**
		 * @param count
		 *            the count to set
		 */
		public void setCount(long count) {
			this.count = count;
		}

		/**
		 * @return the time
		 */
		public Date getTime() {
			return time;
		}

		/**
		 * @param time
		 *            the time to set
		 */
		public void setTime(Date time) {
			this.time = time;
		}

		private ShopCarVo getOuterType() {
			return ShopCarVo.this;
		}

	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Set<Prod> prodList = new HashSet<Prod>();

	public float getTotalPrice() {
		float total = 0;
		for (Prod p : prodList) {
			total += p.getTotalPrice();
		}
		return total;
	}

	public void add(Prod p) {
		prodList.add(p);
	}

	public void delete(Prod p) {
		prodList.remove(p);
	}

	public void clear() {
		prodList.clear();
	}

	/**
	 * @return the prodList
	 */
	public Set<Prod> getProdList() {
		return prodList;
	}

	/**
	 * @param prodList
	 *            the prodList to set
	 */
	public void setProdList(Set<Prod> prodList) {
		this.prodList = prodList;
	}

	public int getCount() {
		return prodList.size();
	}
}